import hashlib
import uuid
import string
import random


def header_md5_str(txt):
    """md5加密"""
    return hashlib.new("md5", txt.encode("utf8")).hexdigest()


def header_has_guuid():
    """生成唯一guuid"""
    guuid = uuid.uuid1()
    return str(guuid)


def has_chocode(len=3, level=0):
    """返回随机数"""
    chars = string.digits
    if level > 0:
        chars += string.ascii_letters
    if level > 1:
        chars += string.punctuation
    return "".join(random.choice(chars) for _ in range(len))
